package cn.mesmile.workflow.process.vo;

import cn.mesmile.workflow.constant.WorkFlowConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.flowable.engine.history.HistoricProcessInstance;

import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * @author zb
 * @Description
 */
@ApiModel(description = "流程定义相关")
@Data
public class DoneProcessVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("流程定义key")
    private String processDefKey;

    @ApiModelProperty("流程定义名称")
    private String processDefName;

    @ApiModelProperty("开始时间")
    private Date startTime;

    @ApiModelProperty("结束时间")
    private Date endTime;

    @ApiModelProperty("结束流程累计用时,单位毫秒")
    private Long durationInMillis;

    @ApiModelProperty("流程实例名称")
    private String name;

    @ApiModelProperty("历史变量")
    private Map<String, Object> variables;

    @ApiModelProperty("发起人")
    private String applyUser;

    @ApiModelProperty("发起人姓名")
    private String applyUserName;

    @ApiModelProperty("删除原因")
    private String deleteReason;

    @ApiModelProperty("流程实例id")
    private String processInstanceId;

    @ApiModelProperty("流程定义id")
    private String processDefinitionId;

    public DoneProcessVO(HistoricProcessInstance instance) {
        this.durationInMillis = instance.getDurationInMillis();
        this.startTime = instance.getStartTime();
        this.processDefKey = instance.getProcessDefinitionKey();
        this.processDefName = instance.getProcessDefinitionName();
        this.endTime = instance.getEndTime();
        this.name = instance.getName();
        this.variables = instance.getProcessVariables();
        this.applyUser = instance.getStartUserId();
        this.applyUserName = (String) variables.get(WorkFlowConstant.PROCESS_APPLY_USER_NAME);
        this.deleteReason = instance.getDeleteReason();
        this.processInstanceId = instance.getId();
        this.processDefinitionId = instance.getProcessDefinitionId();
    }

    public DoneProcessVO(){}
}
